<template>
    <van-search v-model="searchval" shape="round" background="#4fc08d" placeholder="请输入搜索关键词" />
    <van-skeleton title :row="20" v-show="gjp" />
    <van-cell-group v-for="item in qsearchApiData" >
        <router-link :to="{ name: 'goods', params: { query: item.goods_name } }">
            <van-cell :value="item.goods_name" />
        </router-link>
    </van-cell-group>
    <van-empty description="暂无搜索数据" v-show="kongstatus" />
</template>

<script setup>
import { qsearchApi } from '@/api/api';
import _ from 'lodash';
import { ref, watch } from 'vue';
let searchval = ref('')
let qsearchApiData = ref([])
let kongstatus = ref(false)
let gjp = ref(false)
watch(searchval, _.debounce(val => {
    qsearchApi(val).then(res => {
        console.log('搜索数据', res)
        qsearchApiData.value = res.data.message
        if (res.data.message.length == 0) {
            kongstatus.value = true
        } else {
            kongstatus.value = false
        }
    })
}, 2000))
</script>

<style lang="scss" scoped></style>